<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>农集社</title>
    <link rel="stylesheet" type="text/css" href="../css/base.css">
    <link rel="stylesheet" type="text/css" href="../css/discuss_detail.css">
    <link rel="stylesheet" href="../touchTouch/css/styles.css" />
    <link rel="stylesheet" href="../touchTouch/css/touchTouch.css" />
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script src="../interface/interface.js"></script>
</head>
<body>
<div class="content">
    <div class="header" style="background: #ffffff">
        <p class="title">详情 <i onclick="history.go(-1)" class="titleIonc"></i></p>
    </div>
    <div class="main" style="padding-bottom: 0px;margin-top: 40px ">
        <ul class="goodsparents1">
            <li class="goods_show">
            </li>
        </ul>
    </div>
</div>
<div class="pingIun">
    <p class="pingluntitle">全部回答</p>
    <ul class="goodsparents">

    </ul>
    <div class="load">
        <div class="loader-inner ball-spin-fade-loader">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
</div>
<div class="nodata" style="display: none;text-align: center">没有更多数据</div>
<footer id="footer" ></footer>
<div class="footer">
    <input type="text" id="content" placeholder="分享你的见解">
    <p id="send" onclick="drop(this,data['article_id'])" >发送</p>
</div>
<div class="goTop" style="display:none ">
    <img src="../images/gotop_b.png" alt="">
</div>

<script type="text/javascript" src="../js/config.js"></script>
<script type="text/javascript" src="../js/startmove.js"></script>
<script type="text/javascript" src="../js/zepto.min.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/template.js"></script>
<script type="text/javascript" src="../touchTouch/js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="../touchTouch/js/touchTouch.jquery_xiugai.js"></script>
<script type="text/javascript" src="../js/tmpl/footer.js"></script>
<script>
    var is_login = 0;
    var key = getCookie('key');
//    alert(key);
    (function(rf){
        var themeid = '';
        var opt = function(){};
        opt.prototype.getDoms = {
            goodsparent : $('.goodsparents'),
            gooddetails : $('.goodsparents1'),
            goTop:$('.goTop'),
            send:$('#send'),
        };
        opt.prototype.getQueryString = function(name){
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r!=null) return r[2]; return '';
        }
        opt.prototype.template = function(data){
            var text = '';
            for(var i=0;i<data.length;i++) {
                text += '<li class="goods_show" style="padding:10px 0px;margin-bottom: 2px"> ' +
                    '<div class="top paddings"> ' +
                    '<div class="img"> ' ;
                if (data[i]['avatar']==null) {
                    text += '<img src="../images/default_user_portrait.gif" alt=""> ';
                }else{
                    text += '<img src="'+data[i]["avatar"]+'" />';
                }
                text += '</div> ' +
                    '<div class="text"> ' +
                    '<p>'+data[i]['member']['member_name']+'</p> ' +
                    '<p> '+data[i]['date']+'</p> ' +
                    '</div> ' +
                    '</div> ' +
                    '<div class="textmiaoshu paddings"> ' +
                    '<p>'+data[i]['comment_message']+'</p> ' +
                    '</div></li>'
            }
//            console.log(text);
            this.getDoms.goodsparent.append(text);
        };
        opt.prototype.template2 = function(data){
//            console.log(data);
            var text = '';
            text += '<li class="goods_show">';
            text += '<div class="top paddings">';
            text += '<div class="img">';
            if (data['avatar']==null) {
                text += '<img src="/data/upload/shop/common/default_user_portrait.gif?0.17620300 1484978714" alt="">';
            }else{
                text += '<img src="'+data["avatar"]+'" />'
            }
            text += '</div>';
            text += '<div class="text">';
            text += '<p>'+data["article_author"]+'</p>';
            text += '<p>'+data["date"]+'</p>';
            text += '</div>';
            text += '</div>';
            text += "<a>"
            text += '<div class="textmiaoshu paddings">';
            text += '<p>'+data["article_content"]+'</p>';
            text += '</div>';
            text += '</a>';
            text += '<div class="list_footer">';
            text += '<div class="paddings">';
            text += '<p class="look">'+data["article_click"]+'</p>';
//            text += '<p class="good">'+data["article_comment_count"]+'</p>';
            text += '<p class="good" >'+data["article_comment_count"]+'</p>';
            text += '</div>';
            text += '</div>';
            text += '</li>';
            this.getDoms.gooddetails.html(text);
        }
        $('.goTop').on('click', function () {
            $(document).scrollTop(0);
        })
        $('#send').on('click',function(){
            var content = $('#content').val();
            if(!key){
                creatLayout("请登录");
                return false;
            }
            if(content==''){
                creatLayout("你还没填写回复呢");
                return false;
            }
            opt = {
                url:ApiUrl+"/index.php?act=article&op=comment_save&comment_type=article&comment_object_id="+themeid+"&comment_message="+content+"&key="+key,
                type:'GET'
            }
            rf.getData(opt,function(data){
                if(data['result']) {
                    $("#content").val("");
                    var text = '';
                    text += '<li class="goods_show" style="padding:10px 0px;margin-bottom: 2px"> ' +
                        '<div class="top paddings"> ' +
                        '<div class="img"> ' ;
                    if (data["member_avatar"]==null) {
                        text += '<img src="../images/default_user_portrait.gif" alt=""> ';
                    }else{
                        text += '<img src="'+data["member_avatar"]+'" />';
                    }
                    text += '</div> ' +
                        '<div class="text"> ' +
                        '<p>'+data['member_name']+'</p> ' +
                        '<p> '+data['comment_time']+'</p> ' +
                        '</div> ' +
                        '</div> ' +
                        '<div class="textmiaoshu paddings"> ' +
                        '<p>'+data['comment_message']+'</p> ' +
                        '</div></li>';
                    var goodsparents = document.getElementsByClassName('goodsparents')[0];
                    goodsparents.innerHTML = text + goodsparents.innerHTML;
                }
            })
        })
        opt.prototype.init = function(){
            var index = 1;
            var _slef = this;
            var c_id = _slef.getQueryString('article_id');
            opt = {
                url:SITEURL+"/mobile/index.php?act=article&op=article_detail&article_id="+c_id,
                type:'GET',
            }
            opt1 = {
                url:SITEURL+"/cms/index.php?act=comment&op=wapcomment_list&type=article&comment_object_id="+c_id+"&comment_all=",
                type:'GET',
            }
            rf.getData(opt,function(data){
                var reply = data['datas']['reply'];
                var Theme = data['datas']['article'];
                themeid = Theme['article_id'];
                if (data['code']==200){
                    _slef.template2(Theme);
                    document.getElementsByClassName('load')[0].style.display = 'none';
                }
                if(data['datas']['code'] == 400){
                    window.location.href=WapSiteUrl+'/tmpl/member/login.html';
                }
            })
            rf.getData(opt1,function(data){
                var comment = data['data'];
                if (data['code']==200){
                    if(isEmptyJson(comment)){
                         $(".goodsparents").html("<p style='text-align: center'>暂无评论</p>")
                    }else{
                        _slef.template(comment);
                        document.getElementsByClassName('load')[0].style.display = 'none';
                    }

                }
                if(data['code'] == 400){
                    window.location.href=WapSiteUrl+'/tmpl/member/login.html';
                }
            })
           //下拉刷新
            var page = 1;
            var key = getCookie('key');
            var isLock = false;
            $(window).scroll(function () {
                var windowheight = $(window).height();//窗口高度
                var scrolltop = $('body').scrollTop();//滚动条高度
                var eh = $(document).height();//文本高度
                if (parseInt(windowheight + scrolltop)+2 >= eh && isLock == false) {
                    isLock = true;
                    page++;
                    $.ajax({
                        type:"GET",
                        url:opt1.url+"&page="+page,
                        data:{key:key},
                        dataType:"json",
                        success:function(data){
                            var comment = data['data'];
                            if (data['code']==200){
                                if (isEmptyJson(comment)){
                                      $(".nodata").show();
                                }else{
                                    _slef.template(comment);
                                    document.getElementsByClassName('load')[0].style.display = 'none';
                                }
                            }
                            isLock = false;
                        }
                    })
                    //alert('123');
                }
            })
        }
        var i = new opt();
        i.init();

    })(window)

    function isEmptyJson(json) {
          for(k in json){
                return 0
          }
          return 1;
    }

    function drop(_this,article_id){
        if(!is_login){
            creatLayout("请先登录");
            return;
        }
        var url = "/mobile/index.php?act=comment&op=comment_list&t_id="+article_id;
        $.ajax({
            type:"GET",
            url:url,
            dataType:"json",
            success:function(res){
                if(res){
                    creatLayout("评论成功");
                    _this.innerHTML = parseInt(_this.innerHTML)+1;
                }else{
                    creatLayout("你已经评论成功");
                }
            }
        })
    }

</script>